#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>

int main(int argc,char const *argv[])
{
    pid_t pid = fork();
    if (pid > 0)
    {
       printf("父进程开始运行\n");
        int status;
        waitpid(pid,&status,0);   
        printf("子进程已结束，状体：%d\n",status); 
    }else if (pid == 0)
    {
        // for(int i=0;i<10;i++)
        // {
            char *path = "/bin/ping";
            char *arg[]={"ping","www.baidu.com","-c","10",NULL};
            char *env[]={NULL};
           int ret = execve(path,arg,env);
           if (ret ==-1)
           {
                perror("execve failed:");
                _exit(EXIT_FAILURE);
           }
           
        // }
    }
    
    printf("整个程序执行完成 \n");
}